﻿USE [iLangl]
GO


CREATE TABLE [dbo].[iLanglSession](
	[SessionId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[Time] [datetime] NOT NULL,
 CONSTRAINT [PK_Session] PRIMARY KEY CLUSTERED 
(
	[SessionId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE PROCEDURE iLangl_sp_CreateSession
@UserId uniqueidentifier
AS

SET NOCOUNT ON

DECLARE @SessionId uniqueidentifier

SET @SessionId = newid()

INSERT INTO iLanglSession(SessionId, UserId, [Time])
VALUES(@SessionId, @Userid, getdate())

SELECT @SessionID

GO

CREATE PROCEDURE iLangl_sp_ReadSession
@SessionId uniqueidentifier
AS

SET NOCOUNT ON

SELECT
	ses.SessionId,
	ses.UserId,
	ses.Time,
	aspU.UserName UserName
From iLanglSession ses
Join aspnet_Users aspU on aspU.UserId = ses.UserId
WHERE
	SessionId = @SessionId

GO